<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['basic']=$return['pluginset'];
if($_RQ['op']=='main'){
	cfc('core')->checklogin();
	$tomid=intval($_RQ['tomid']);
	$tcpid=intval($_RQ['tcpid']);
	$workerid=intval($_RQ['workerid']);
	if(!$tcpid && !$tomid){
		$tomid=pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid']),'id');
	}
	$item=$this->model('kefu')->gettcp($tcpid,$tomid);
	$tomid=$item['tomid']==$_SESSION['uid']?$item['mid']:$item['tomid'];
	if(!$item['id']){
		exi('当前对话不存在','error',$return['backurl']);
	}
	if($_RQ['pluginname']){
		$_SESSION['pluginname']=$_RQ['pluginname'];
	}
	if($_SESSION['pluginname']){
		$return['backurl']=custom_url($_SESSION['pluginname'].'/tcplog//endcall=1&tomid='.$tomid,true);
	}else{
		$return['backurl']=custom_url('jy_ailiao/tcplog//endcall=1&tomid='.$tomid,true);
	}
	$member=model('core/member')->detail($_SESSION['uid']);
	$member['nickname']=$member['nickname']?:$member['username'];
	$return['member']=$member;
	$tomember=model('core/member')->detail($tomid);
	$tomember['nickname']=$tomember['nickname']?:$tomember['username'];
	$tomember['avatar']=$tomember['avatar']?tomedia($tomember['avatar']):'../addons/jy_videocall/resource/call/default_avatar.png';
	$return['tomember']=$tomember;
	$return['item']=$item;
	$return['toroomtype']=($item['status']==1 || $item['status']==2)?1:2;
	//$return['toroomtype']=1;
	$return['uid']=$_SESSION['uid'];
	$return['upmeet_idurl']=SITEROOT.'api.php?this=custom&token='.$_SESSION['token'].'&plugin=jy_videocall&action=index&op=upmeet_id&tcpid='.$item['id'];
	$return['tomeet_idurl']=SITEROOT.'api.php?this=custom&token='.$_SESSION['token'].'&plugin=jy_videocall&action=index&op=tomeet_id&tcpid='.$item['id'];
	$return['isgua']=$_RQ['isgua'];
	include $this->template('index');
	//exi($return);
}
if($_RQ['op']=='upmeet_id'){
	//file_put_contents(ROOT_D.'/1.txt',ijson_encode($_RQ));
	$tcpid=intval($_RQ['tcpid']);
	pdo_update('jy_videocall_tcp',array('meet_id'=>$_RQ['meet_id'],'status'=>1,'callmid'=>$_SESSION['uid'],'tocalltime'=>time()),array('id'=>$tcpid,'uniacid'=>$_SESSION['uniacid']));
	if($_SESSION['pluginname']){
		$tcp=pdo_get('jy_videocall_tcp',array('uniacid'=>$_SESSION['uniacid'],'id'=>$tcpid));
		$tomid=$tcp['mid']==$_SESSION['uid']?$tcp['tomid']:$tcp['mid'];
		//file_put_contents(ROOT_D.'/2.txt',$tomid.'~~'.$tcpid);
		model($_SESSION['pluginname'].'/kefu')->videocall($tomid,'',1);
	}
	exi('success');
}
if($_RQ['op']=='tomeet_id'){
	//file_put_contents(ROOT_D.'/1.txt',ijson_encode($_RQ));
	$tcpid=intval($_RQ['tcpid']);
	pdo_update('jy_videocall_tcp',array('status'=>2,'calltime'=>time()),array('id'=>$tcpid,'uniacid'=>$_SESSION['uniacid']));
	if($_SESSION['pluginname']){
		$tcp=pdo_get('jy_videocall_tcp',array('uniacid'=>$_SESSION['uniacid'],'id'=>$tcpid));
		$tomid=$tcp['mid']==$_SESSION['uid']?$tcp['tomid']:$tcp['mid'];
		model($_SESSION['pluginname'].'/kefu')->videocall($tomid,'',2);
	}
	exi('success');
}